package com.bum.sock.poll.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.core.task.TaskExecutor;

import com.bum.api.core.exp.om.Metas;
import com.bum.api.core.exp.om.Params;
import com.bum.sock.poll.bo.ChatBO;
import com.bum.sock.poll.bo.Loader;
import com.bum.sock.poll.util.RequestUtil;

public class ChatServlet extends HttpServlet {
	private static final long	serialVersionUID	= 1L;

	private ChatBO				chatBO				= Loader.getBean("chatBO");

	TaskExecutor				executor			= Loader.getBean("executor");

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
		process(request, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
		process(request, resp);
	}

	private void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
		final Params params = RequestUtil.getParams(request);
		final Metas metas = RequestUtil.getMetas(request);
		
		executor.execute(new Runnable() {
			@Override
			public void run() {
				chatBO.process(params, metas);
			}
		});
	}

}
